package com.itheima.item.web;

import com.itheima.item.pojo.GoodInfo;
import com.itheima.item.service.GoodService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("item")
public class ItemController {
    @Autowired
    private GoodService goodService;
    @GetMapping("findByPage/{pageNum}/{pageSize}")
    public List<GoodInfo> findByPage(@PathVariable("pageNum") Integer pageNum,@PathVariable("pageSize") Integer pageSize){
        return goodService.findByPage(pageNum,pageSize);
    }

    @GetMapping("findGoodsById/{id}")
    public GoodInfo findGoodsById(@PathVariable("id")Long id){
        return goodService.findGoodsById(id);
    }

    @DeleteMapping("deleteById/{id}")
    public Boolean deleteById(@PathVariable("id")Long id){
        return goodService.deleteAndSendMsg(id);
    }

   @PostMapping("addOrUpdate")
   public Boolean addOrUpdate(@RequestBody GoodInfo goodInfo){
        return goodService.addOrUpdate(goodInfo);
   }




    @GetMapping("count")
    public Integer count(){
        return goodService.count();
    }

}
